/**
 * Classe de gestion du mot de passe
* @author I.T. Works.
* @date 18/12/2011
* @version 1.0
*/
package org.itworks.biodev.gui.panels;

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.*;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import org.itworks.biodev.gui.*;
import org.itworks.biodev.model.Customer;
import org.itworks.helpers.MVCNotification;

import org.itworks.biodev.model.*;
import org.itworks.helpers.*;

public class ParametersPanelView extends JPanel {

	private static ParametersPanelView parametersPanelView = null;
	private MainWindowView parent = null;
	private ParametersPanelControler controler = null;
	
	private JPasswordField confirmNewPasswordField;
    private JLabel confirmNewPasswordLabel;
    private JPasswordField newPasswordField;
    private JLabel newPasswordLabel;
    private JPasswordField oldPasswordField;
    private JLabel oldPasswordLabel;
    private JLabel parametersTitleLabel;
    private JButton validationButton;
   
    /**Constructeur de la classe */
    private ParametersPanelView(MainWindowView parent, ParametersPanelControler controler) {
    	this.parent = parent;
		this.controler = controler;
				
		initComponents();
		initHandlers();
		
		this.controler.viewLoaded();
    }

    /**Agencement des onglets et boutons */
    private void initComponents() {

        parametersTitleLabel = new javax.swing.JLabel();
        oldPasswordLabel = new javax.swing.JLabel();
        newPasswordLabel = new javax.swing.JLabel();
        validationButton = new javax.swing.JButton();
        confirmNewPasswordLabel = new javax.swing.JLabel();
        newPasswordField = new javax.swing.JPasswordField();
        confirmNewPasswordField = new javax.swing.JPasswordField();
        oldPasswordField = new javax.swing.JPasswordField();

        parametersTitleLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 18));
        parametersTitleLabel.setText("Modifier mot de passe");

        oldPasswordLabel.setText("Ancien mot de passe :");

        newPasswordLabel.setText("Nouveau mot de passe :");

        validationButton.setText("Valider");

        confirmNewPasswordLabel.setText("Nouveau mot de passe :");

        newPasswordField.setText("jPasswordField1");
        newPasswordField.setMaximumSize(new java.awt.Dimension(117, 27));
        newPasswordField.setMinimumSize(new java.awt.Dimension(117, 27));

        confirmNewPasswordField.setText("jPasswordField2");
        confirmNewPasswordField.setAutoscrolls(true);
        confirmNewPasswordField.setMaximumSize(new java.awt.Dimension(117, 27));
        confirmNewPasswordField.setMinimumSize(new java.awt.Dimension(117, 27));

        oldPasswordField.setText("jPasswordField3");
        oldPasswordField.setMaximumSize(new java.awt.Dimension(117, 27));
        oldPasswordField.setMinimumSize(new java.awt.Dimension(117, 27));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(parametersTitleLabel)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(confirmNewPasswordLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                                    .addComponent(confirmNewPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 100,javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(newPasswordLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                                    .addComponent(newPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 100,javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(oldPasswordLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                                    .addComponent(oldPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 100,javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(925, 925, 925))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(validationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(1163, Short.MAX_VALUE))))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {confirmNewPasswordField, newPasswordField, oldPasswordField});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(parametersTitleLabel)
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(oldPasswordLabel)
                    .addComponent(oldPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newPasswordLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(newPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(confirmNewPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(confirmNewPasswordLabel))
                .addGap(35, 35, 35)
                .addComponent(validationButton)
                .addContainerGap(464, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {confirmNewPasswordField, newPasswordField, oldPasswordField});

    }
    
    /** Gestion du comportement des boutons*/
    private void initHandlers() {
		this.validationButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				controler.validationButtonActionPerformed(actionEvent, oldPasswordField.getPassword(), newPasswordField.getPassword(), confirmNewPasswordField.getPassword());
			}
			
		});

	}
    
    /**Si la fenetre de parametre n'est pas affichee on l'affiche*/
    public static ParametersPanelView getInstance(MainWindowView parent) {
    	if(parametersPanelView == null) {
    		parametersPanelView = new ParametersPanelView(parent, new ParametersPanelControler(new ParametersPanelModel()));
    	}
    	
    	return parametersPanelView;
    }
}

